package com.meiqiongproperty.yiguanjia.fragment.order;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.meiqiongproperty.yiguanjia.R;
import com.meiqiongproperty.yiguanjia.activity.GenericFragmentActivity;
import com.meiqiongproperty.yiguanjia.databinding.OrderShopLayoutBinding;
import com.meiqiongproperty.yiguanjia.fragment.BaseFragment;
import com.meiqiongproperty.yiguanjia.fragment.home.adapter.OnItemClickListener;
import com.meiqiongproperty.yiguanjia.fragment.order.orderAdapter.OrderShopListAdapter;
import com.meiqiongproperty.yiguanjia.http.api.ApiService;
import com.meiqiongproperty.yiguanjia.http.interfaces.IHttpCallback;
import com.meiqiongproperty.yiguanjia.http.sendJsonModel.SendShopOrder;
import com.meiqiongproperty.yiguanjia.httpbean.order.ShopOrderBean;
import com.meiqiongproperty.yiguanjia.utils.LogUtil;
import com.meiqiongproperty.yiguanjia.utils.Utils;

import java.util.ArrayList;
import java.util.List;

/**
 * author: Administrator
 * date: 2017/5/14.
 * package:com.meiqiongproperty.yiguanjia.fragment.order
 */

public class OrderShoppingFragment extends BaseFragment {
    OrderShopLayoutBinding binding;
    OrderShopListAdapter adapter;
    List<ShopOrderBean.OrderlistBean> list=new ArrayList<>();
    int OrderType=1;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(inflater, R.layout.order_shop_layout, container, false);


        LinearLayoutManager manager = new LinearLayoutManager(getActivity());
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        binding.recyclerOrderShop.setLayoutManager(manager);

        getShopOrderData();
        return binding.getRoot();
    }

    /**
     * 获取商城订单数据
     */
    public void getShopOrderData() {
        SendShopOrder send = new SendShopOrder();
        send.setToken(Utils.getToken(getActivity()));
        send.setRoomID(Utils.getRoomID(getActivity()));
        send.setOrderType("1");
        send.setPageNo("1");
        send.setPageSize("50");

        ApiService.getShopOrderList(getActivity(), new IHttpCallback<ShopOrderBean>() {
            @Override
            public void onNext(ShopOrderBean shopOrderBean) {
                LogUtil.d("orderShopList============>");
                list.clear();
                list.addAll(shopOrderBean.getOrderlist());
                adapter = new OrderShopListAdapter(getActivity(),list);
                binding.recyclerOrderShop.setAdapter(adapter);

                adapter.setOnItemClickListener(new OnItemClickListener() {
                    @Override
                    public void onItemClick(View view, int position) {
                        Bundle bundle=new Bundle();
                        bundle.putString("payMethod",list.get(position).getPayMethod());
                        bundle.putString("PayStatus",list.get(position).getPayStatus());
                        bundle.putString("orderTitle",list.get(position).getOrderTitle());
                        bundle.putString("orderCreateTime",list.get(position).getCreateAt());
                        bundle.putInt("OrderType",OrderType);
                        bundle.putString("orderId",list.get(position).getOrderId());
                        GenericFragmentActivity.start(getActivity(),OrderDetailFragment.class,bundle);
                    }
                });
            }

            @Override
            public void onError(int code, String message) {

            }
        }, Utils.getRequestBody(send));
    }
}
